package com.sky.controller.admin;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.Intercept;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

@RestController("adminShopController")
@RequestMapping("/admin/shop")
@Slf4j
@Api(tags = "营业状态")
public class ShoppController {
    @Resource
    RedisTemplate redisTemplate;

    public static final String KEY="SHOP_STATUS";
    @PutMapping("{status}")
    @ApiOperation("设置店铺营业状态")
    public Result setUp(@PathVariable Integer status){
        log.info("当前店铺的状态:{}",status==1?"营业中":"打烊");
        redisTemplate.opsForValue().set(KEY,status,1,TimeUnit.DAYS);
       return Result.success();
    }

    @GetMapping("status")
    @ApiOperation("获取店铺营业状态")
    public Result getUp(){
        Integer status = (Integer) redisTemplate.opsForValue().get(KEY);
        log.info("获取店铺营业状态:{}",status==1?"营业中":"打烊");
        return Result.success(status);
    }
}
